/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MainFrame.java
 *
 * Created on 4/Dez/2011, 19:48:42
 */

package intopo.evogame.partnerselection.tools.config;

import intopo.evogame.partnerselection.EvolutionaryAlgorithm;
import intopo.evogame.partnerselection.config.ConstructGameException;
import intopo.evogame.partnerselection.config.ConstructStrategyException;
import intopo.evogame.partnerselection.config.ParsingException;
import intopo.evogame.partnerselection.config.TagException;
import intopo.evogame.partnerselection.config.TextConfigFilePlainPlayersEditor;
import intopo.evogame.partnerselection.config.TextConfigFilePlainPlayersEditor.NodeParameters;

import intopo.game.gui.AbstractGameEditorComponent;
import intopo.util.Util;
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.FlowLayout;
import java.awt.event.KeyEvent;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

/**
 *
 * @author pedro
 */
public class MainFrame
	extends javax.swing.JFrame
{
	private TextConfigFilePlainPlayersEditor configFile;
//	private ConfigParameters parameters;
	final private Options options;
	private int currentStep;
	/**
	 * Config file name;
	 */
	private String configFilename;


    /** Creates new form MainFrame */
	public MainFrame()
	{
		this.options = new Options ();
		this.configFile = new TextConfigFilePlainPlayersEditor (this.options.getGameData ().get (0).description);
//		this.parameters = new ConfigParameters (this.options.getGameData ().get (0).description);
		this.configFilename = "config.txt";
		initComponents ();
		this.currentStep = 0;
		// GUI dynamic content...
		// ... file chooser initial directory
		this.configFileChooser.setCurrentDirectory (new File (this.options.defaultConfigFilename));
		// ... card panel with game parameters 
		this.gameEditorComponent = new AbstractGameEditorComponent [this.options.getGameData ().size ()];
		int i = 0;
		for (Options.GameData gd : this.options.getGameData ()) {
			JPanel panel = new JPanel (new BorderLayout ());
			panel.add (gd.description.getGlobalParametersEditorComponent (), BorderLayout.CENTER);
			this.gameEditorComponent [i] = gd.description.getGameEditorComponent ();
			this.gameEditorComponent [i].addComponentListener (new ComponentAdapter () {
				@Override
				public void componentShown (ComponentEvent e) {
					System.out.println ("Maybe set game?");
				}

				@Override
				public void componentHidden (ComponentEvent e) {
					System.out.println ("Get game");
				}
			});
			panel.add (gameEditorComponent [i], BorderLayout.EAST);
			JPanel front = new JPanel (new FlowLayout ());
			front.add (panel);
			this.step1GamesPanel.add (front, gd.name);
			i++;
		}
//		boolean first = true;
//		geographicInformationMenuItem = new JRadioButtonMenuItem [Information.values ().length];
//		ButtonGroup bg;
//		bg = new ButtonGroup ();
//		i = 0;
//		for (Information info : Information.values ()) {
//			geographicInformationMenuItem [i] = new JRadioButtonMenuItem (info.description, first);
//			geographicInformationMenuItem [i].addActionListener (new ActionListener () {
//
//				@Override
//				public void actionPerformed (ActionEvent e) {
//					int i = 0;
//					for (i = geographicInformationMenuItem.length - 1; i >= 0; i--) {
//						if (e.getSource () == geographicInformationMenuItem [i]) {
//							geographicPopulationComponent.setInformation (Information.values () [i]);
//							return ;
//						}
//					}
//				}
//			});
//			bg.add (geographicInformationMenuItem [i]);
//			this.geographicPopulationComponentPopupMenu.add (geographicInformationMenuItem [i]);
//			first = false;
//			i++;
//		}
	}
	/**
	 * Game editor components that are dynamicaly created.
	 */
	private AbstractGameEditorComponent[] gameEditorComponent;

//	private JRadioButtonMenuItem[] geographicInformationMenuItem;

	/**
	 * Update the components after a configuration file has been loaded.
	 */
	private void updateComponents ()
	{
		this.numberRunsFormattedTextField.setValue (new Integer (EvolutionaryAlgorithm.Parameters.numberRounds));
		this.chromosomeParametersPanel.updateComponents ();
		this.abstractPlayerParametersComponent.updateComponents ();
		this.geographicParametersComponent.updateComponents ();
		this.gameEditorComponent [this.gameComboBox.getSelectedIndex ()].setGame (this.configFile.getGame ());
	}
	/**
	* @param args the command line arguments
	*/
	public static void main (String args[]) {
		try {
			UIManager.setLookAndFeel (UIManager.getSystemLookAndFeelClassName ());
		} catch (ClassNotFoundException ex) {
		} catch (InstantiationException ex) {
		} catch (IllegalAccessException ex) {
		} catch (UnsupportedLookAndFeelException ex) {
		}
		new MainFrame ().setVisible (true);
	}

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
   // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
   private void initComponents() {
      java.awt.GridBagConstraints gridBagConstraints;

      configFileChooser = new javax.swing.JFileChooser();
      toolBar = new javax.swing.JToolBar();
      previousButton = new javax.swing.JButton();
      nextButton = new javax.swing.JButton();
      mainPanel = new javax.swing.JPanel();
      step0Panel = new javax.swing.JPanel();
      gameInitPanel = new javax.swing.JPanel();
      gameImplPanel = new javax.swing.JPanel();
      gameComboBox = new javax.swing.JComboBox (this.options.comboBoxModel ());
      configFileLoadPanel = new javax.swing.JPanel();
      configFilenameTextFieldL = new javax.swing.JTextField();
      openLButton = new javax.swing.JButton();
      loadButton = new javax.swing.JButton();
      step1GamesPanel = new javax.swing.JPanel();
      step2Panel = new javax.swing.JPanel();
      commonParametersPanel = new javax.swing.JPanel();
      javax.swing.JLabel jLabel1 = new javax.swing.JLabel();
      numberRunsFormattedTextField = new javax.swing.JFormattedTextField();
      chromosomeParametersPanel = new intopo.evogame.partnerselection.tools.config.ChromosomeParametersPanel();
      abstractPlayerParametersComponent = new intopo.evogame.partnerselection.tools.config.AbstractPlayerParametersComponent();
      geographicParametersComponent = new GeographicParametersComponent (this.configFile);
      javax.swing.JSplitPane step3PopulationSplitPane = new javax.swing.JSplitPane();
      geographicPopulationScrollPane = new javax.swing.JScrollPane();
      geographicPopulationComponent = new GeographicPopulationComponent (this.configFile);
      nodeParametersComponent = new NodeParametersComponent (this.configFile);
      step4Panel = new javax.swing.JPanel();
      gameFinishPanel = new javax.swing.JPanel();
      configFileSavePanel = new javax.swing.JPanel();
      configFilenameTextFieldS = new javax.swing.JTextField();
      saveButton = new javax.swing.JButton();

      setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
      setTitle("EvoGames configuration editor");
      addWindowListener(new java.awt.event.WindowAdapter() {
         public void windowClosed(java.awt.event.WindowEvent evt) {
            formWindowClosed(evt);
         }
         public void windowClosing(java.awt.event.WindowEvent evt) {
            formWindowClosing(evt);
         }
      });

      toolBar.setRollover(true);

      previousButton.setMnemonic(java.awt.event.KeyEvent.VK_P);
      previousButton.setText("Previous");
      previousButton.setDisplayedMnemonicIndex(0);
      previousButton.setEnabled(false);
      previousButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
      previousButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
      previousButton.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
            previousButtonActionPerformed(evt);
         }
      });
      toolBar.add(previousButton);

      nextButton.setMnemonic(java.awt.event.KeyEvent.VK_N);
      nextButton.setText("Next");
      nextButton.setDisplayedMnemonicIndex(0);
      nextButton.setFocusable(false);
      nextButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
      nextButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
      nextButton.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
            nextButtonActionPerformed(evt);
         }
      });
      toolBar.add(nextButton);

      getContentPane().add(toolBar, java.awt.BorderLayout.NORTH);

      mainPanel.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
      mainPanel.setLayout(new java.awt.CardLayout());

      step0Panel.addComponentListener(new java.awt.event.ComponentAdapter() {
         public void componentHidden(java.awt.event.ComponentEvent evt) {
            configFileLoadPanelComponentHidden(evt);
         }
         public void componentShown(java.awt.event.ComponentEvent evt) {
            configFileLoadPanelComponentShown(evt);
         }
      });

      gameInitPanel.setLayout(new javax.swing.BoxLayout(gameInitPanel, javax.swing.BoxLayout.LINE_AXIS));

      gameImplPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("game"));

      gameComboBox.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
            gameComboBoxActionPerformed(evt);
         }
      });
      gameImplPanel.add(gameComboBox);

      gameInitPanel.add(gameImplPanel);

      configFileLoadPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("config file"));
      configFileLoadPanel.setLayout(new java.awt.GridBagLayout());

      configFilenameTextFieldL.setColumns(20);
      configFilenameTextFieldL.setText(this.options.defaultConfigFilename);
      configFileLoadPanel.add(configFilenameTextFieldL, new java.awt.GridBagConstraints());

      openLButton.setMnemonic(java.awt.event.KeyEvent.VK_O);
      openLButton.setText("Open");
      openLButton.setDisplayedMnemonicIndex(0);
      openLButton.setFocusable(false);
      openLButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
      openLButton.setMargin(new java.awt.Insets(10, 10, 10, 10));
      openLButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
      openLButton.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
            openLButtonActionPerformed(evt);
         }
      });
      configFileLoadPanel.add(openLButton, new java.awt.GridBagConstraints());

      loadButton.setMnemonic(java.awt.event.KeyEvent.VK_L);
      loadButton.setText("Load");
      loadButton.setDisplayedMnemonicIndex(0);
      loadButton.setFocusable(false);
      loadButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
      loadButton.setMargin(new java.awt.Insets(10, 10, 10, 10));
      loadButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
      configFileLoadPanel.add(loadButton, new java.awt.GridBagConstraints());

      gameInitPanel.add(configFileLoadPanel);

      step0Panel.add(gameInitPanel);

      mainPanel.add(step0Panel, "step0");

      step1GamesPanel.setLayout(new java.awt.CardLayout());
      mainPanel.add(step1GamesPanel, "step1");

      commonParametersPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("common parameters"));
      commonParametersPanel.setLayout(new java.awt.GridBagLayout());

      jLabel1.setText("number runs: ");
      gridBagConstraints = new java.awt.GridBagConstraints();
      gridBagConstraints.gridx = 0;
      gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
      commonParametersPanel.add(jLabel1, gridBagConstraints);

      numberRunsFormattedTextField.setColumns(5);
      numberRunsFormattedTextField.setValue(new Integer (intopo.evogame.partnerselection.EvolutionaryAlgorithm.Parameters.numberRounds));
      numberRunsFormattedTextField.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
         public void propertyChange(java.beans.PropertyChangeEvent evt) {
            numberRunsFormattedTextFieldPropertyChange(evt);
         }
      });
      gridBagConstraints = new java.awt.GridBagConstraints();
      gridBagConstraints.gridx = 1;
      gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
      commonParametersPanel.add(numberRunsFormattedTextField, gridBagConstraints);

      chromosomeParametersPanel.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
         public void propertyChange(java.beans.PropertyChangeEvent evt) {
            chromosomeParametersPanelPropertyChange(evt);
         }
      });
      gridBagConstraints = new java.awt.GridBagConstraints();
      gridBagConstraints.gridx = 0;
      gridBagConstraints.gridwidth = 2;
      commonParametersPanel.add(chromosomeParametersPanel, gridBagConstraints);
      gridBagConstraints = new java.awt.GridBagConstraints();
      gridBagConstraints.gridx = 0;
      gridBagConstraints.gridwidth = 2;
      gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
      commonParametersPanel.add(abstractPlayerParametersComponent, gridBagConstraints);

      geographicParametersComponent.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
         public void propertyChange(java.beans.PropertyChangeEvent evt) {
            geographicParametersComponentPropertyChange(evt);
         }
      });
      gridBagConstraints = new java.awt.GridBagConstraints();
      gridBagConstraints.gridx = 0;
      gridBagConstraints.gridwidth = 2;
      gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
      commonParametersPanel.add(geographicParametersComponent, gridBagConstraints);

      step2Panel.add(commonParametersPanel);

      mainPanel.add(step2Panel, "step2");

      geographicPopulationComponent.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
         public void propertyChange(java.beans.PropertyChangeEvent evt) {
            geographicPopulationComponentPropertyChange(evt);
         }
      });
      geographicPopulationScrollPane.setViewportView(geographicPopulationComponent);

      step3PopulationSplitPane.setLeftComponent(geographicPopulationScrollPane);
      step3PopulationSplitPane.setRightComponent(nodeParametersComponent);

      mainPanel.add(step3PopulationSplitPane, "step3");

      step4Panel.addComponentListener(new java.awt.event.ComponentAdapter() {
         public void componentHidden(java.awt.event.ComponentEvent evt) {
            configFileSavePanelComponentHidden(evt);
         }
         public void componentShown(java.awt.event.ComponentEvent evt) {
            configFileSavePanelComponentShown(evt);
         }
      });

      gameFinishPanel.setLayout(new javax.swing.BoxLayout(gameFinishPanel, javax.swing.BoxLayout.LINE_AXIS));

      configFileSavePanel.setBorder(javax.swing.BorderFactory.createTitledBorder("config file"));

      configFilenameTextFieldS.setColumns(20);
      configFilenameTextFieldS.setText(this.options.defaultConfigFilename);
      configFileSavePanel.add(configFilenameTextFieldS);

      saveButton.setMnemonic(KeyEvent.VK_S);
      saveButton.setText("Save");
      saveButton.setFocusable(false);
      saveButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
      saveButton.setMargin(new java.awt.Insets(10, 10, 10, 10));
      saveButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
      saveButton.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
            saveButtonActionPerformed(evt);
         }
      });
      configFileSavePanel.add(saveButton);

      gameFinishPanel.add(configFileSavePanel);

      step4Panel.add(gameFinishPanel);

      mainPanel.add(step4Panel, "step4");

      getContentPane().add(mainPanel, java.awt.BorderLayout.CENTER);

      pack();
   }// </editor-fold>//GEN-END:initComponents

	 private void previousButtonActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_previousButtonActionPerformed
		 this.currentStep--;
		 CardLayout layout = (CardLayout) this.mainPanel.getLayout ();
		 layout.show (this.mainPanel, "step" + this.currentStep);
		 if (this.currentStep == 0) {
			 this.previousButton.setEnabled (false);
			 this.setTitle ("EvoGames configuration editor");
		 }
		 this.nextButton.setEnabled (true);
}//GEN-LAST:event_previousButtonActionPerformed

	 private void nextButtonActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nextButtonActionPerformed
		 this.currentStep++;
		 CardLayout layout = (CardLayout) this.mainPanel.getLayout ();
		 layout.show (this.mainPanel, "step" + this.currentStep);
		 if (this.currentStep == this.mainPanel.getComponents ().length - 1) {
			 this.nextButton.setEnabled (false);
		 }
		 this.previousButton.setEnabled (true);
		 int index = this.gameComboBox.getSelectedIndex ();
		 this.setTitle (this.options.comboBoxModel () [index]);
}//GEN-LAST:event_nextButtonActionPerformed

	 private void gameComboBoxActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_gameComboBoxActionPerformed
		CardLayout layout = (CardLayout) this.step1GamesPanel.getLayout ();
		layout.show (this.step1GamesPanel, this.gameComboBox.getSelectedItem ().toString ());
		int index = this.gameComboBox.getSelectedIndex ();
		this.configFile.setDescription (this.options.getGameData ().get (index).description);
		this.nodeParametersComponent.gameChanged ();
		this.geographicPopulationComponent.descriptionChanged ();
}//GEN-LAST:event_gameComboBoxActionPerformed

	 private void numberRunsFormattedTextFieldPropertyChange (java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_numberRunsFormattedTextFieldPropertyChange
		if (evt.getPropertyName ().equals ("value")) {
			final int nr = (Integer) this.numberRunsFormattedTextField.getValue ();
			final boolean ok = nr > 0;
			if (ok) {
				EvolutionaryAlgorithm.Parameters.numberRounds = nr;
			}
			Util.update (this.numberRunsFormattedTextField, ok);
		}
}//GEN-LAST:event_numberRunsFormattedTextFieldPropertyChange

	 private void chromosomeParametersPanelPropertyChange (java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_chromosomeParametersPanelPropertyChange
		if (evt.getPropertyName ().equals ("chromosome")) {
			this.nodeParametersComponent.genericChromosomeParametersChanged ();
		} else {
			System.out.println ("chromosomeParametersPanel property changed: " + evt.getPropertyName ());
		}
}//GEN-LAST:event_chromosomeParametersPanelPropertyChange

	 private void geographicParametersComponentPropertyChange (java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_geographicParametersComponentPropertyChange
		if (evt.getPropertyName ().equals ("population")) {
			this.geographicPopulationComponent.parametersChanged ();
		}
}//GEN-LAST:event_geographicParametersComponentPropertyChange

	 private void saveButtonActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveButtonActionPerformed
		this.configFilename = this.configFilenameTextFieldS.getText ();
		try {
			int index = this.gameComboBox.getSelectedIndex ();

			this.configFile.setGame (this.gameEditorComponent [index].getGame ());
			this.configFile.write (this.configFilename);
		}
		catch (FileNotFoundException e) {
			JOptionPane.showMessageDialog (this,
				"Could not save config file '" + this.configFilename + "'\n"
				+ "Detailed message:\n"
				+ e.getLocalizedMessage (),
				"IO Error", JOptionPane.ERROR_MESSAGE);
		}
}//GEN-LAST:event_saveButtonActionPerformed

	 private void geographicPopulationComponentPropertyChange (java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_geographicPopulationComponentPropertyChange
		if (evt.getPropertyName ().equals ("selectedNode")) {
			NodeParameters nodeParameters = (NodeParameters) evt.getNewValue ();
			this.nodeParametersComponent.setNode (nodeParameters);
		}
//		System.out.println (" geographicPopulationComponentPropertyChange : " + evt.getPropertyName ());
}//GEN-LAST:event_geographicPopulationComponentPropertyChange

	 private void configFileLoadPanelComponentShown (java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_configFileLoadPanelComponentShown
		this.configFilenameTextFieldL.setText (this.configFilename);
		//System.out.println ("c -> L");
	 }//GEN-LAST:event_configFileLoadPanelComponentShown

	 private void configFileLoadPanelComponentHidden (java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_configFileLoadPanelComponentHidden
		this.configFilename = this.configFilenameTextFieldL.getText ();
		//System.out.println ("L -> c");
	 }//GEN-LAST:event_configFileLoadPanelComponentHidden

	 private void configFileSavePanelComponentShown (java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_configFileSavePanelComponentShown
		this.configFilenameTextFieldS.setText (this.configFilename);
		//System.out.println ("c -> S");
	 }//GEN-LAST:event_configFileSavePanelComponentShown

	 private void configFileSavePanelComponentHidden (java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_configFileSavePanelComponentHidden
		this.configFilename = this.configFilenameTextFieldS.getText ();
//		System.out.println ("S -> c");
	 }//GEN-LAST:event_configFileSavePanelComponentHidden

	 private void openLButtonActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openLButtonActionPerformed
		int ret = this.configFileChooser.showOpenDialog (this);
		if (ret == JFileChooser.APPROVE_OPTION) {
			String filename = this.configFileChooser.getSelectedFile ().getPath ();
			try {
				this.configFile.read (filename);
				this.configFilenameTextFieldL.setText (filename);
				this.options.defaultConfigFilename = filename;
				this.updateComponents ();
			}
			catch (ParsingException ex) {
				String message;
				message = "Error parsing configuration file + '" + configFilename + "'";
				if (ex.getContents () == null) {
					message += ".\nNo line available";
				}
				else {
					message += " at line '" + ex.getContents () + "'";
				}
				JOptionPane.showMessageDialog (this, message, "Load error", JOptionPane.ERROR_MESSAGE);
			}
			catch (TagException ex) {
				JOptionPane.showMessageDialog (this, ex.getUserMessage () + "\n\n" +
					"Tag does not match any in the game:\n"
					+ ex.getTag (),
					"Load error", JOptionPane.ERROR_MESSAGE);
			}
			catch (ConstructGameException ex) {
				JOptionPane.showMessageDialog (this,
					"Error creating the game:\n"
					+ ex.getDescription () + "\n"
					+ ex.getLocalizedMessage (),
					"Load error", JOptionPane.ERROR_MESSAGE);
			}
			catch (ConstructStrategyException ex) {
				JOptionPane.showMessageDialog (this,
					"Error creating a strategy associatated to tag:\n"
					+ ex.getTagName () + "\n"
					+ "Detailed error message:\n"
					+ ex.getLocalizedMessage (),
					"Load error", JOptionPane.ERROR_MESSAGE);
			}
			catch (FileNotFoundException ex) {
				JOptionPane.showMessageDialog (this, "File not found:\n" + filename + "\n" + ex.getLocalizedMessage (), "Load error", JOptionPane.ERROR_MESSAGE);
			}
			catch (IOException ex) {
				JOptionPane.showMessageDialog (this, "Error loading file:\n" + filename + "\n\n" + ex.getMessage (), "Load error", JOptionPane.ERROR_MESSAGE);
			}
		}
	 }//GEN-LAST:event_openLButtonActionPerformed

	 private void formWindowClosed (java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
		
	 }//GEN-LAST:event_formWindowClosed

	 private void formWindowClosing (java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
		this.options.save ();
		System.out.println ("Saved options 2");
	 }//GEN-LAST:event_formWindowClosing



   // Variables declaration - do not modify//GEN-BEGIN:variables
   private intopo.evogame.partnerselection.tools.config.AbstractPlayerParametersComponent abstractPlayerParametersComponent;
   private intopo.evogame.partnerselection.tools.config.ChromosomeParametersPanel chromosomeParametersPanel;
   private javax.swing.JPanel commonParametersPanel;
   private javax.swing.JFileChooser configFileChooser;
   private javax.swing.JPanel configFileLoadPanel;
   private javax.swing.JPanel configFileSavePanel;
   private javax.swing.JTextField configFilenameTextFieldL;
   private javax.swing.JTextField configFilenameTextFieldS;
   private javax.swing.JComboBox gameComboBox;
   private javax.swing.JPanel gameFinishPanel;
   private javax.swing.JPanel gameImplPanel;
   private javax.swing.JPanel gameInitPanel;
   private intopo.evogame.partnerselection.tools.config.GeographicParametersComponent geographicParametersComponent;
   private intopo.evogame.partnerselection.tools.config.GeographicPopulationComponent geographicPopulationComponent;
   private javax.swing.JScrollPane geographicPopulationScrollPane;
   private javax.swing.JButton loadButton;
   private javax.swing.JPanel mainPanel;
   private javax.swing.JButton nextButton;
   private intopo.evogame.partnerselection.tools.config.NodeParametersComponent nodeParametersComponent;
   private javax.swing.JFormattedTextField numberRunsFormattedTextField;
   private javax.swing.JButton openLButton;
   private javax.swing.JButton previousButton;
   private javax.swing.JButton saveButton;
   private javax.swing.JPanel step0Panel;
   private javax.swing.JPanel step1GamesPanel;
   private javax.swing.JPanel step2Panel;
   private javax.swing.JPanel step4Panel;
   private javax.swing.JToolBar toolBar;
   // End of variables declaration//GEN-END:variables

}
